#include "StompedReality/Core/TypeSystem/TypeSystem.h"
#include "StomperLib/Controls/Property/NumberProperty.h"
#include "StomperLib/Controls/Property/PropertyFactory.h"
#include "StomperLib/Controls/Property/StringProperty.h"
#include "StomperLib/Controls/Property/Vector2Property.h"
namespace StomperLib {
namespace Controls {
namespace Property {

void PropetyFactory::InitText( Gwen::Controls::Properties* base, StomperLib::EditorObjectInfo* object,
                               StomperLib::Controls::Property::TextPropertyBase* prop,
                               StompedReality::type_system::TypeField field,
                               std::string label )
{
  prop->SetName( label );
  prop->SetDataPointer( object->GetDataPointer( ) + field.offset );
  base->Add( label, prop );
  prop->CopyDataToValue( );
}

void PropetyFactory::InitNumber( Gwen::Controls::Properties* base, StomperLib::EditorObjectInfo* object,
                                 StomperLib::Controls::Property::NumericPropertyBase* prop,
                                 StompedReality::type_system::TypeField field,
                                 std::string label )
{
  prop->SetName( label );
  prop->SetDataPointer( object->GetDataPointer( ) + field.offset );
  base->Add( label, prop );
  prop->CopyDataToValue( );

}

Gwen::Controls::Property::Base* PropetyFactory::CreateProperty( StomperLib::EditorObjectInfo* object,
                                                                std::string fieldName, std::string label,
                                                                Gwen::Controls::Properties* base )
{
  StompedReality::type_system::TypeField field = object->TypeInfo->findField( fieldName.c_str( ));
  if (field.type == StompedReality::type_system::TypeSystem::GetTypeID( "Vector2" ))
  {
    StomperLib::Controls::Property::Vector2Property* prop = new StomperLib::Controls::Property::Vector2Property( base );
    InitText( base, object, prop, field, label );
    return prop;
  }
  else if (field.type == StompedReality::type_system::TypeSystem::GetTypeID( "string" ))
  {
    StomperLib::Controls::Property::StringProperty* prop = new StomperLib::Controls::Property::StringProperty( base );
    InitText( base, object, prop, field, label );
    return prop;
  }
  else if (field.type == StompedReality::type_system::TypeSystem::GetTypeID( "uint" ))
  {
    StomperLib::Controls::Property::NumberProperty* prop = new StomperLib::Controls::Property::NumberProperty( base );
    InitNumber( base, object, prop, field, label );
    return prop;
  }
  return 0;
}

}
}
}